package com.bright.tactiviti.process.start;


import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

@SpringBootTest
public class ProcessVariableNote {

    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;
    /**
     * 启动流程
     */

    @Test
    public void processStartByKey(){
        //流程变量
        Map<String,Object> variableMap = getVariableMap("assigneeVariable", "userA");
        String processDefinitionKey = "fileProcess";

        // 启动流程时放入key、流程变量
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, variableMap);

        System.out.println("流程启动成功，流程实例ID：" + processInstance.getProcessInstanceId());
    }

    /**
     * 获取流程变量
     *
     * @param key key
     * @param value value
     * @return Map 集合
     */
    private Map<String, Object> getVariableMap(String key, Object value) {
        HashMap<String, Object> variableMap = new HashMap<>(16);
        variableMap.put(key, value);

        return variableMap;
    }
}
